"I have worked long & hard with Robert. He will do a great job!" Trump tweeted.
Last week, Trump abruptly fired John Bolton, a vigorous proponent of using US military force abroad and one of the main hawks in the administration on Iran.
O'Brien has until now served as Trump's envoy for situations involving US hostages abroad.
He comes into the new job with backing from Secretary of State Mike Pompeo and senior Republicans in Congress.
Bolton, by contrast, was a highly controversial figure in Washington. His instincts for an aggressive, interventionist foreign policy were at odds with Trump's more isolationist stance. Bolton "wasn't getting along with people in the administration who I consider very important" and "wasn't in line with what we were doing," Bolton said. O'Brien will become the fourth national security advisor in Trump's tumultuous first term.
He arrives just as Trump is coming under pressure from some in Washington to go to war with Iran in retaliation for an attack on oil facilities in Saudi Arabia last weekend that has been blamed on Tehran.
Moments before naming O'Brien as his new advisor, Trump announced he was ordering "substantially" increased sanctions against Iran, which is already buckling under US economic pressure.